﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;

namespace Groupware
{
    public class EventManager
    {

        public static void DeleteEvent(int eventId)
        {
            Storage.StorageManager.Instance.DeleteEventById(eventId);
        }

        public static Storage.EntityModels.Event GetEventById(int eventId)
        {
            return Storage.StorageManager.Instance.GetEventById(eventId);
        }

        #region mappings

        public static List<Trip> getTripsByEventId(int eventId)
        {
            var result = from trip_events in Storage.StorageManager.Instance.Entities.Trips_Events
                         where trip_events.EventId == eventId
                         select trip_events.Trip;
            List<Trip> list = new List<Trip>();
            foreach (Storage.EntityModels.Trip st in result)
            {
                Trip t = new Trip(st);
                list.Add(t);
            }
            return list;
        }

        public static List<Event> getEventsByTripId(int tripId)
        {
            var result = from trip_events in Storage.StorageManager.Instance.Entities.Trips_Events
                         where trip_events.TripId == tripId
                         select trip_events.Event;
            List<Event> list = new List<Event>();
            foreach (Storage.EntityModels.Event se in result)
            {
                Event e = new Event(se);
                list.Add(e);
            }
            return list;
        }

        #endregion
    }
}
